home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevm8.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  7.4 KB  |  239 lines

  1. /* Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdevm8.c,v 1.2 2000/09/19 19:00:13 lpd Exp $ */
  20. /* 8-bit-per-pixel "memory" (stored bitmap) device */
  21. #include "memory_.h"
  22. #include "gx.h"
  23. #include "gxdevice.h"
  24. #include "gxdevmem.h"        /* semi-public definitions */
  25. #include "gdevmem.h"        /* private definitions */
  26.  
  27. #define mem_gray8_strip_copy_rop mem_gray8_rgb24_strip_copy_rop
  28.  
  29. /* ================ Standard (byte-oriented) device ================ */
  30.  
  31. #undef chunk
  32. #define chunk byte
  33.  
  34. /* Procedures */
  35. declare_mem_procs(mem_mapped8_copy_mono, mem_mapped8_copy_color, mem_mapped8_fill_rectangle);
  36.  
  37. /* The device descriptor. */
  38. const gx_device_memory mem_mapped8_device =
  39. mem_device("image8", 8, 0,
  40.        mem_mapped_map_rgb_color, mem_mapped_map_color_rgb,
  41.   mem_mapped8_copy_mono, mem_mapped8_copy_color, mem_mapped8_fill_rectangle,
  42.        mem_gray8_strip_copy_rop);
  43.  
  44. /* Convert x coordinate to byte offset in scan line. */
  45. #undef x_to_byte
  46. #define x_to_byte(x) (x)
  47.  
  48. /* Fill a rectangle with a color. */
  49. private int
  50. mem_mapped8_fill_rectangle(gx_device * dev,
  51.                int x, int y, int w, int h, gx_color_index color)
  52. {
  53.     gx_device_memory * const mdev = (gx_device_memory *)dev;
  54.  
  55.     fit_fill(dev, x, y, w, h);
  56.     bytes_fill_rectangle(scan_line_base(mdev, y) + x, mdev->raster,
  57.              (byte) color, w, h);
  58.     return 0;
  59. }
  60.  
  61. /* Copy a monochrome bitmap. */
  62. /* We split up this procedure because of limitations in the bcc32 compiler. */
  63. private void mapped8_copy01(P9(chunk *, const byte *, int, int, uint,
  64.                    int, int, byte, byte));
  65. private void mapped8_copyN1(P8(chunk *, const byte *, int, int, uint,
  66.                    int, int, byte));
  67. private void mapped8_copy0N(P8(chunk *, const byte *, int, int, uint,
  68.                    int, int, byte));
  69. private int
  70. mem_mapped8_copy_mono(gx_device * dev,
  71.            const byte * base, int sourcex, int sraster, gx_bitmap_id id,
  72.     int x, int y, int w, int h, gx_color_index zero, gx_color_index one)
  73. {
  74.     gx_device_memory * const mdev = (gx_device_memory *)dev;
  75.     const byte *line;
  76.     int first_bit;
  77.  
  78.     declare_scan_ptr(dest);
  79.     fit_copy(dev, base, sourcex, sraster, id, x, y, w, h);
  80.     setup_rect(dest);
  81.     line = base + (sourcex >> 3);
  82.     first_bit = 0x80 >> (sourcex & 7);
  83. #define is_color(c) ((int)(c) != (int)gx_no_color_index)
  84.     if (is_color(one)) {
  85.     if (is_color(zero))
  86.         mapped8_copy01(dest, line, first_bit, sraster, draster,
  87.                w, h, (byte) zero, (byte) one);
  88.     else
  89.         mapped8_copyN1(dest, line, first_bit, sraster, draster,
  90.                w, h, (byte) one);
  91.     } else if (is_color(zero))
  92.     mapped8_copy0N(dest, line, first_bit, sraster, draster,
  93.                w, h, (byte) zero);
  94. #undef is_color
  95.     return 0;
  96. }
  97. /* Macros for copy loops */
  98. #define COPY_BEGIN\
  99.     while ( h-- > 0 )\
  100.     {    register byte *pptr = dest;\
  101.         const byte *sptr = line;\
  102.         register int sbyte = *sptr;\
  103.         register uint bit = first_bit;\
  104.         int count = w;\
  105.         do\
  106.         {
  107. #define COPY_END\
  108.             if ( (bit >>= 1) == 0 )\
  109.                 bit = 0x80, sbyte = *++sptr;\
  110.             pptr++;\
  111.         }\
  112.         while ( --count > 0 );\
  113.         line += sraster;\
  114.         inc_ptr(dest, draster);\
  115.     }
  116. /* Halftone coloring */
  117. private void
  118. mapped8_copy01(chunk * dest, const byte * line, int first_bit,
  119.            int sraster, uint draster, int w, int h, byte b0, byte b1)
  120. {
  121.     COPY_BEGIN
  122.     * pptr = (sbyte & bit ? b1 : b0);
  123.     COPY_END
  124. }
  125. /* Stenciling */
  126. private void
  127. mapped8_copyN1(chunk * dest, const byte * line, int first_bit,
  128.            int sraster, uint draster, int w, int h, byte b1)
  129. {
  130.     COPY_BEGIN
  131.     if (sbyte & bit)
  132.     *pptr = b1;
  133.     COPY_END
  134. }
  135. /* Reverse stenciling */
  136. private void
  137. mapped8_copy0N(chunk * dest, const byte * line, int first_bit,
  138.            int sraster, uint draster, int w, int h, byte b0)
  139. {
  140.     COPY_BEGIN
  141.     if (!(sbyte & bit))
  142.     *pptr = b0;
  143.     COPY_END
  144. }
  145. #undef COPY_BEGIN
  146. #undef COPY_END
  147.  
  148. /* Copy a color bitmap. */
  149. private int
  150. mem_mapped8_copy_color(gx_device * dev,
  151.            const byte * base, int sourcex, int sraster, gx_bitmap_id id,
  152.                int x, int y, int w, int h)
  153. {
  154.     gx_device_memory * const mdev = (gx_device_memory *)dev;
  155.  
  156.     fit_copy(dev, base, sourcex, sraster, id, x, y, w, h);
  157.     mem_copy_byte_rect(mdev, base, sourcex, sraster, x, y, w, h);
  158.     return 0;
  159. }
  160.  
  161. /* ================ "Word"-oriented device ================ */
  162.  
  163. /* Note that on a big-endian machine, this is the same as the */
  164. /* standard byte-oriented-device. */
  165.  
  166. #if !arch_is_big_endian
  167.  
  168. /* Procedures */
  169. declare_mem_procs(mem8_word_copy_mono, mem8_word_copy_color, mem8_word_fill_rectangle);
  170.  
  171. /* Here is the device descriptor. */
  172. const gx_device_memory mem_mapped8_word_device =
  173. mem_full_device("image8w", 8, 0, mem_open,
  174.         mem_mapped_map_rgb_color, mem_mapped_map_color_rgb,
  175.     mem8_word_copy_mono, mem8_word_copy_color, mem8_word_fill_rectangle,
  176.         gx_default_map_cmyk_color, gx_default_strip_tile_rectangle,
  177.         gx_no_strip_copy_rop, mem_word_get_bits_rectangle);
  178.  
  179. /* Fill a rectangle with a color. */
  180. private int
  181. mem8_word_fill_rectangle(gx_device * dev, int x, int y, int w, int h,
  182.              gx_color_index color)
  183. {
  184.     gx_device_memory * const mdev = (gx_device_memory *)dev;
  185.     byte *base;
  186.     uint raster;
  187.  
  188.     fit_fill(dev, x, y, w, h);
  189.     base = scan_line_base(mdev, y);
  190.     raster = mdev->raster;
  191.     mem_swap_byte_rect(base, raster, x << 3, w << 3, h, true);
  192.     bytes_fill_rectangle(base + x, raster, (byte) color, w, h);
  193.     mem_swap_byte_rect(base, raster, x << 3, w << 3, h, true);
  194.     return 0;
  195. }
  196.  
  197. /* Copy a bitmap. */
  198. private int
  199. mem8_word_copy_mono(gx_device * dev,
  200.            const byte * base, int sourcex, int sraster, gx_bitmap_id id,
  201.     int x, int y, int w, int h, gx_color_index zero, gx_color_index one)
  202. {
  203.     gx_device_memory * const mdev = (gx_device_memory *)dev;
  204.     byte *row;
  205.     uint raster;
  206.     bool store;
  207.  
  208.     fit_copy(dev, base, sourcex, sraster, id, x, y, w, h);
  209.     row = scan_line_base(mdev, y);
  210.     raster = mdev->raster;
  211.     store = (zero != gx_no_color_index && one != gx_no_color_index);
  212.     mem_swap_byte_rect(row, raster, x << 3, w << 3, h, store);
  213.     mem_mapped8_copy_mono(dev, base, sourcex, sraster, id,
  214.               x, y, w, h, zero, one);
  215.     mem_swap_byte_rect(row, raster, x << 3, w << 3, h, false);
  216.     return 0;
  217. }
  218.  
  219. /* Copy a color bitmap. */
  220. private int
  221. mem8_word_copy_color(gx_device * dev,
  222.            const byte * base, int sourcex, int sraster, gx_bitmap_id id,
  223.              int x, int y, int w, int h)
  224. {
  225.     gx_device_memory * const mdev = (gx_device_memory *)dev;
  226.     byte *row;
  227.     uint raster;
  228.  
  229.     fit_copy(dev, base, sourcex, sraster, id, x, y, w, h);
  230.     row = scan_line_base(mdev, y);
  231.     raster = mdev->raster;
  232.     mem_swap_byte_rect(row, raster, x << 3, w << 3, h, true);
  233.     mem_copy_byte_rect(mdev, base, sourcex, sraster, x, y, w, h);
  234.     mem_swap_byte_rect(row, raster, x << 3, w << 3, h, false);
  235.     return 0;
  236. }
  237.  
  238. #endif /* !arch_is_big_endian */
  239.